/*
 * @Description:
 * @Date: 2021-09-15 11:33:13
 * @LastEditTime: 2021-09-16 16:21:36
 */

function getMessge(
  langs: Record<string, Record<string, any>>,
  prefix = 'lang'
) {
  const obj: Record<string, any> = {}
  Object.keys(langs).forEach((item) => {
    const langFileModule = langs[item].default
    // 清除前缀和后缀名
    let fileName = item.replace(`./${prefix}/`, '').split('.')[0]

    const fileList = fileName.split('/')

    if (fileList.length === 1) {
      obj[fileName] = langFileModule
    } else {
      const firstName = fileList[0]
      const lastName = fileList[1]
      obj[firstName] = {}
      obj[firstName][lastName] = langFileModule
    }
  })

  return obj
}
export { getMessge }
